<template>
  <div>
    <!-- 一条文章单元格 -->
    <van-cell>
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span>{{ title }}</span>
          <img class="thumb" alt="" v-if="cover.type === 1" v-lazy="cover.images[0]" />
        </div>
        <div class="thumb-box" v-if="cover.type > 1">
          <img v-for="(item, index) in cover.images" :key="index" class="thumb" alt="" v-lazy="item" />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <!--彩蛋 -->
      <template #label>
        <div class="label-box">
          <div>
            <span>作者:{{ name }}</span>
            <span>{{ comm }}评论</span>
            <span>{{ timeF(timer) }}</span>
          </div>
          <!-- 反馈按钮 -->
          <van-icon name="cross" @click.stop="show = true" v-if="isSHwo" />
        </div>
      </template>
    </van-cell>
    <van-action-sheet v-model="show" :actions="actions" @select="onSelect" @cancel="cancelFn" @close="closeFn"
      get-container="body" :cancel-text="bottonTetx" />
  </div>
</template>

<script>
import { timeAgo } from '@/utils/date.js'
import { firstActions, secondActions } from '@/api/report.js'
export default {
  methods: {
    timeF: timeAgo,
    closeFn() {
      console.log(1);
      this.actions = firstActions
      this.bottonTetx = '取消'
    },
    cancelFn() {
      if (this.bottonTetx === '返回') {
        this.show = true
        this.actions = firstActions
        this.bottonTetx = '取消'
      }
    },
    onSelect(item) {
      if (item.name === '反馈垃圾内容') {
        this.bottonTetx = '返回'
        this.actions = secondActions
      } else if (item.name === '不感兴趣') {
        this.$emit('disLike', this.id)
        this.show = false
      } else {
        this.$emit('reportEV', this.id, item.value)
        this.show = false
      }
    }
  },
  data() {
    return {
      show: false,
      actions: firstActions,
      bottonTetx: '取消'
    }
  },

  props: {
    isSHwo: {
      default: true,
      type: Boolean
    },
    id: {
      default: '',
      type: String
    },
    name: {
      default: '',
      type: String
    },
    title: {
      default: '',
      type: String
    },
    comm: {
      default: 0,
      type: Number
    },
    timer: {
      default: '',
      type: String
    },

    cover: {
      default: {},
      type: Object
    }
  }
}
</script>

<style scoped lang="less">
/* 标题样式 */
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* label描述样式 */
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 文章信息span */
.label-box span {
  margin: 0 3px;

  &:first-child {
    margin-left: 0;
  }
}

/* 图片的样式, 矩形黄金比例：0.618 */
.thumb {
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}

/* 三图, 图片容器 */
.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>
